package com.bzframework.pro.authorize.entity;

import com.bzframework.pro.authorize.enums.UserRoleEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.DefaultValue;
import org.hswebframework.ezorm.rdb.mapping.annotation.EnumCodec;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import org.hswebframework.web.api.crud.entity.RecordCreationEntity;
import org.hswebframework.web.api.crud.entity.RecordModifierEntity;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.crud.generator.Generators;

import javax.persistence.Column;
import javax.persistence.Table;

/**
 * @Author bingzhong
 * @Date 2024/11/22 15:32
 * @Description
 */
@Table(name = "s_user")
@Getter
@Setter
@Schema(description = "示例实体类")
@EnableEntityEvent //开启实体类crud事件
public class UserEntity extends GenericEntity<String>
//实现这2个接口标记此实体类需要记录创建人修改人信息，在crud时会自动填充对应的信息。
        implements RecordCreationEntity, RecordModifierEntity {

    @Column
    @Schema(description = "姓名")
    private String name;

    @Column(unique = true)
    @Schema(description = "用户名")
    private String username;

    @Column(length = 2048)
    @Schema(description = "头像")
    private String avatar;

    @Column
    @Schema(description = "密码")
    private String password;

    @Column
    @Schema(description = "邮箱")
    private String email;

    @Column
    @Schema(description = "年龄")
    private Integer age;

    @Column
    @Schema(description = "性别")
    private Integer gender;

    @Column(length = 64)
    @Schema(description = "电话")
    private String telephone;

    @Column(length = 512)
    @Schema(description = "描述")
    private String description;

    @Column
    @DefaultValue(generator = Generators.SNOW_FLAKE)
    @Schema(description = "加密盐值")
    private String salt;

    @Column
    @EnumCodec
    @DefaultValue("user")
    @ColumnType(javaType = String.class)
    @Schema(description = "用户角色")
    private UserRoleEnum role;

    //平台ID长度mobile;统一64,创建人不为空,不可修改
    @Column(length = 64, updatable = false)
    @Schema(description = "创建人ID", accessMode = Schema.AccessMode.READ_ONLY)
    private String creatorId;

    @Column(updatable = false)
    @DefaultValue(generator = Generators.CURRENT_TIME)
    @Schema(description = "创建时间", accessMode = Schema.AccessMode.READ_ONLY)
    private Long createTime;

    @Column(length = 64)
    @Schema(description = "修改人ID", accessMode = Schema.AccessMode.READ_ONLY)
    private String modifierId;

    @Column
    @DefaultValue(generator = Generators.CURRENT_TIME)
    @Schema(description = "修改时间", accessMode = Schema.AccessMode.READ_ONLY)
    private Long modifyTime;

}
